home *** CD-ROM | disk | FTP | other *** search
- Path: sol.caps.maine.edu!news
- From: aspenc51 <aspenc51@maine.maine.edu>
- Newsgroups: comp.lang.c++
- Subject: ***Newbie Help with arrays and linker errors!!!***
- Date: Wed, 20 Mar 1996 15:04:12 -0500
- Organization: University of Maine System
- Message-ID: <315064BC.287C@maine.maine.edu>
- NNTP-Posting-Host: async11.ts-caps4.caps.maine.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- I'm just starting to learn programming, and I've run into a sort of block with arrays. I've got this simple die
- roller that rolls 4 six-sideds and subtracts the lowest of the 4 from the total, and I just can't get it to work.
- I've looked for errors, but there are no complier problems my wrench-in-the-works is a single linker error.
- (undefined symbol 'minimum(int, int)' in module 'diceroll.cpp') Can someone show me where things are running amuck?
- This thing's driving me crazy! Just please e-mail me with your suggestions since my news server kind of only half
- works.
-
- Here's the program (written under Borland 4.52 C++)
-
- /* This is a simple die roller program code
- ** roll individual dice and total them or
- ** 4d6 - lowest... it keeps popping up with a fatal linker error
- ** that I'm positive is related to the arrays or
- ** at least the functions calling arrays*/
-
- #include <iostream.h>
- #include <iomanip.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- int randadd(int, int);
- int minimum(int, int);
- int main()
- {
- int sides,
- rolls,
- value,
- start;
- value=0;
-
- cout<<"Roll for Character or Single? 1,0"; cin>>start; cout<<endl<<endl; //really simple menu
- while (start==0)
- {
- cout<<"Enter number of dice "; cin>>rolls; cout<<rolls<<"d"<<endl;
- cout<<" Enter number of sides "; cin>>sides; cout<<rolls<<"d"<<sides<<endl;
-
- value=randadd(rolls, sides);
- cout<<value;
- }
- while (start==-1) //just stuff to loop and break
- {
- return(0);
- }
- while (start==1) //character roller
- {
- int counter;
- counter=6;
- while (counter > 0)
- {
- counter=counter-1;
- int roll1=randadd(1, 6),
- roll2=randadd(1, 6),
- roll3=randadd(1, 6),
- roll4=randadd(1, 6),
- roll_array[4]={roll1, roll2, roll3, roll4}; //4d6 - lowest
-
- value=(roll1+roll2+roll3+roll4)-(minimum(roll_array[4] , 4)); //error seems here
- cout<<value<<endl;
- }
- cin>>start;
- if (start !=1)
- return 0;
- }
- }
-
- int randadd(int rolls, int sides) //rolling function
- {
- int add;
- add=0;
-
- while(rolls > 0)
- {
- rolls=(rolls-1);
- add=add+(rand() % sides) +1;
- }
- return add;
- }
-
- int minimum( int roll_array[], int length) //finds minimum value
- {
- int minSoFar;
-
- if (length==1)
- return roll_array[0];
- else
- {
- minSoFar=minimum(roll_array, length-1);
- if (roll_array[length-1]<minSoFar)
- return roll_array[length-1];
- else
- return minSoFar;
- }
- }
-